package com.jbm.jbmsupplier.activity.searchconstrucation.mode

import com.jbm.core.iface.IAcross
import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.InterfaceMaArr
import com.jbm.jbmsupplier.activity.rxjavanet.ModeRxjavaNet
import com.jbm.onehome.iface.LoginEntity
import rx.Observable
import rx.Observer

/**
 * Created by 家帮忙 on 2017/8/24.
 */
class Serch_Mode_Con :Serch_Mode_ConInter<String,LoginEntity> {
    override fun setSerchCont(phot: String, onclickliner: InterfaceMaArr<String, LoginEntity>) {
        if(!phot.equals("")){
            ModeRxjavaNet.getInstantMode().objects(Observable.create(Observable.OnSubscribe <LoginEntity>{
                oblogin->
                oblogin.onNext(ModeRxjavaNet.getInstantMode().getOhInter().GetLogin(0,phot,"",""))
            })).subscribe(object :Observer<LoginEntity>{
                override fun onError(e: Throwable?) {
                }
                override fun onNext(t: LoginEntity?) {
                    if (t?.m_code==200){
                        var arraylis=ArrayList<LoginEntity>();
                        arraylis.add(t)
                        onclickliner.onSuccess(t.loginId.toString(),true,arraylis)
                    }else{
                        onclickliner.setError(t?.m_info!!,false)
                    }

                }

                override fun onCompleted() {
                }

            })
        }
    }

    override fun setSerchAddFriend(phot: String, onclickliner: InterfaceMa<String>) {

            ModeRxjavaNet.getInstantMode().objects(Observable.create(Observable.OnSubscribe <IAcross>{
                oblogin->
                oblogin.onNext(ModeRxjavaNet.getInstantMode().getOhInter().addtoUnit(Integer.parseInt(phot)))
            })).subscribe(object :Observer<IAcross>{
                override fun onError(e: Throwable?) {
                }
                override fun onNext(t: IAcross?) {
                    if (t?.m_code==200){
                        onclickliner.onSuccess("",true)
                    }else{
                        onclickliner.setError(t?.m_info!!,false)
                    }

                }

                override fun onCompleted() {
                }

            })




   }


}